home *** CD-ROM | disk | FTP | other *** search
- /*
- Copyright © 1993-1997 Fabrizio Oddone
- ••• ••• ••• ••• ••• ••• ••• ••• ••• •••
- This source code is distributed as freeware:
- you may copy, exchange, modify this code.
- You may include this code in any kind of application: freeware,
- shareware, or commercial, provided that full credits are given.
- You may not sell or distribute this code for profit.
- */
-
-
- #include "UtilsSys7.h"
- #include "Conversions.h"
- #include "FabWList.h"
- #include "Independents.h"
- #include "SimResIDs.h"
-
- #include "Globals.h"
- #include "Animation.h"
- #include "ControlStore.h"
- #include "DoEditDialog.h"
- #include "DoMenu.h"
- #include "Main.h"
- #include "Registers.h"
-
- #if defined(FabSystem7orlater)
-
-
- static GrafPtr sOffScr; /* offscreen GrafPort for animation */
- static PicHandle sImages[kLAST_PICT - kFIRST_PICT + 1]; /* Handles to Pictures */
- static Rect sRval[kP_MIR - kP_ALATCH + kMIRSubboxes]; /* in these rects we write the values */
- static RgnHandle sMirUpdRgn;
-
-
-
- static Boolean PtInObj(Point, Rect * const, short obj);
-
-
- #pragma segment Init
- /* Init_Animation: initializes the Animation Window */
-
- OSErr Init_Animation(void)
- {
- static const short initial[] = { kP_REGISTERS, kC_ALU2MSL1, kC_ALU2MSL2, kP_MIR, kP_TEXT, 0 };
-
- Rect tempRect;
- BitMap offBits;
- FabWindowPtr thefabw;
- WindowPtr w;
- PicHandle tempPH;
- RgnHandle theRgn;
- short rightLong;
- short count, i;
- OSErr err = appMemFullErr;
-
- gWPtr_Animation = w = GetNewWindow(kWIND_Animation, nil, (WindowPtr)-1L);
- if (w) {
- SetPortWindowPort(w);
- if (gPrefs.remembWind)
- if (IsOnScreenWeak(gPrefs.AnimTopLeft))
- MoveWindow(w, gPrefs.AnimTopLeft.h, gPrefs.AnimTopLeft.v, false);
- ClipRect(&w->portRect);
- offBits.bounds = w->portRect;
- rightLong = ((offBits.bounds.right + 15) >> 4) << 1;
- offBits.rowBytes = rightLong;
- if (sOffScr = (GrafPtr)NewPtrClear(sizeof(GrafPort))) {
- OpenPort(sOffScr);
- if (offBits.baseAddr = NewPtrClear(rightLong * (long)offBits.bounds.bottom)) {
- SetPortBits(&offBits);
- TextFont(monaco);
- ClipRect(&offBits.bounds);
- PenPat(&qd.gray);
- PenMode(notPatBic);
- sMirUpdRgn = NewRgn();
- {
- register RgnHandle tempRgn = NewRgn();
- register PicHandle *PictScan;
- register RectPtr RectScan;
-
- for (RectScan = sRval, PictScan = sImages, count = kFIRST_PICT;
- count <= kLAST_PICT; count++) {
- register PicHandle tempPicH;
-
- tempPicH = GetPicture(count);
- *PictScan++ = tempPicH;
- tempRect = (*tempPicH)->picFrame;
- DrawPicture(tempPicH, &tempRect);
- RectRgn(tempRgn, &tempRect);
- PaintRgn(tempRgn);
- if( count <= kP_MPC ) {
- --tempRect.bottom;
- --tempRect.right;
- InsetRect(&tempRect, 3, 3);
- *RectScan++ = tempRect;
- }
- else if( count == kP_ALU ) {
- tempRect.bottom -= 4;
- tempRect.right -= 15;
- tempRect.left += 15;
- tempRect.top = tempRect.bottom - 15;
- *RectScan++ = tempRect;
- }
- else if( count == kP_MSL ) {
- tempRect.bottom -= 3;
- tempRect.top += 3;
- tempRect.right -= 3;
- tempRect.left += 19;
- *RectScan++ = tempRect;
- }
- else if( count == kP_MIR ) {
- register int ind;
-
- tempRect.bottom -= 2;
- ++tempRect.left;
- tempRect.top = tempRect.bottom - 15;
- tempRect.right = tempRect.left + 11;
- for( ind = 0; ind <= 12; ind++) {
- *RectScan++ = tempRect;
- RectRgn(tempRgn, &tempRect);
- UnionRgn(sMirUpdRgn, tempRgn, sMirUpdRgn);
- tempRect.left += 12;
- tempRect.right += 12;
- }
- tempRect.right += 11;
- *RectScan = tempRect;
- RectRgn(tempRgn, &tempRect);
- UnionRgn(sMirUpdRgn, tempRgn, sMirUpdRgn);
- }
- }
- DisposeRgn(tempRgn);
- }
- ChangedAllBoxes();
- ActivateObjs(initial);
-
- thefabw = AddWindowToList(w);
- SetUpdate(thefabw, Update_Animation);
- SetGoAway(thefabw, CloseAnimation);
- SetContent(thefabw, Do_Animation);
-
- SetPortWindowPort(w);
- for (i = kP_ALATCH - kFIRST_PICT; i <= kP_MAP - kFIRST_PICT; i++) {
- theRgn = NewRgn();
- tempPH = sImages[i];
- if (*tempPH == nil)
- LoadResource((Handle)tempPH);
- tempRect = (*tempPH)->picFrame;
- RectRgn(theRgn, &tempRect);
- InstallRgnHandler(thefabw, theRgn, nil, nil,
- toMenu(kBalloons_Anim, i + 1), 6, 0);
- }
- // there are no resizable objects in this window
- // ResizeObjects(w);
-
- RecalcGlobalCoords(thefabw);
-
- err = noErr;
- }
- }
- }
- return err;
- }
-
-
- #pragma segment Main
- /*
- PtInObj: finds out if thePt is in the obj object, returning the object
- Rect in neededRect */
-
- static Boolean PtInObj(Point thePt, Rect * const neededRect, short obj)
- {
- register PicHandle tempPH;
-
- tempPH = sImages[obj];
- if (*tempPH == nil) // handle was purged
- LoadResource((Handle)tempPH);
- *neededRect = (*tempPH)->picFrame;
- neededRect->right--;
- neededRect->bottom--;
- return(PtInRect(thePt, neededRect));
- }
-
- /*
- UpdateMir: takes care of updating the mir image in the Animation window */
-
- void UpdateMir(un_mir newmir)
- {
- Str255 tempS;
- GrafPtr savePort;
- register RectPtr RectScan = &sRval[kP_MIR - kP_ALATCH];
-
- GetPort(&savePort);
- SetPort(sOffScr);
- MyNumToString((newmir).bits.amux, tempS);
- TETextBox(&tempS[1], StrLength(tempS), RectScan++, teJustCenter);
- MyNumToString((newmir).bits.cond, tempS);
- TETextBox(&tempS[1], StrLength(tempS), RectScan++, teJustCenter);
- MyNumToString((newmir).bits.alu, tempS);
- TETextBox(&tempS[1], StrLength(tempS), RectScan++, teJustCenter);
- MyNumToString((newmir).bits.shift, tempS);
- TETextBox(&tempS[1], StrLength(tempS), RectScan++, teJustCenter);
- MyNumToString((newmir).bits.mbr, tempS);
- TETextBox(&tempS[1], StrLength(tempS), RectScan++, teJustCenter);
- MyNumToString((newmir).bits.rd, tempS);
- TETextBox(&tempS[1], StrLength(tempS), RectScan++, teJustCenter);
- MyNumToString((newmir).bits.wr, tempS);
- TETextBox(&tempS[1], StrLength(tempS), RectScan++, teJustCenter);
- MyNumToString((newmir).bits.mar, tempS);
- TETextBox(&tempS[1], StrLength(tempS), RectScan++, teJustCenter);
- MyNumToString((newmir).bits.dsc, tempS);
- TETextBox(&tempS[1], StrLength(tempS), RectScan++, teJustCenter);
- ShortToHexString((newmir).bits.a, tempS);
- TETextBox(&tempS[4], 1, RectScan++, teJustCenter);
- ShortToHexString((newmir).bits.b, tempS);
- TETextBox(&tempS[4], 1, RectScan++, teJustCenter);
- ShortToHexString((newmir).bits.c, tempS);
- TETextBox(&tempS[4], 1, RectScan++, teJustCenter);
- MyNumToString((newmir).bits.map, tempS);
- TETextBox(&tempS[1], StrLength(tempS), RectScan++, teJustCenter);
- MyNumToString((newmir).bits.addr, tempS);
- TETextBox(&tempS[1], StrLength(tempS), RectScan++, teJustRight);
- SetPort(gWPtr_Animation);
- InvalRgn(sMirUpdRgn);
- SetPort(savePort);
- }
-
- /* ChangedBox: does all the housekeeping when an on-screen object is modified */
-
- void ChangedBox(int obj)
- {
- Str255 tempS;
- GrafPtr savePort;
-
- GetPort(&savePort);
- SetPort(sOffScr);
- ShortToHexString(gParts[obj], tempS);
- if((obj >= kP_INCR - kFIRST_PICT)&&(obj <= kP_MPC - kFIRST_PICT)) {
- *(Byte *)(&gParts[obj]) = 0;
- MyNumToString(gParts[obj], tempS);
- }
- else {
- if( obj == kP_ALU - kFIRST_PICT ) {
- register unsigned char *mslstring = (unsigned char *)&tempS + 8;
- register StringPtr ZeroandOne = *GetString(kSTR_BINALLOWED);
-
- *mslstring++ = (gParts[kP_ALU - kFIRST_PICT] < 0 ? *(ZeroandOne+2) : *(ZeroandOne+1));
- *mslstring++ = 13;
- *mslstring++ = (gParts[kP_ALU - kFIRST_PICT] == 0 ? *(ZeroandOne+2) : *(ZeroandOne+1));
- TextSize(9);
- TETextBox((unsigned char *)&tempS + 8, 3, &sRval[kP_MSL - kFIRST_PICT], teJustCenter);
- TextSize(12);
- }
- }
- TETextBox(&tempS[1], StrLength(tempS), &sRval[obj], teJustCenter);
- SetPort(gWPtr_Animation);
- InvalRect(&sRval[obj]);
- if (obj == kP_ALU - kFIRST_PICT)
- InvalRect(&sRval[kP_MSL - kFIRST_PICT]);
- SetPort(savePort);
- }
-
- void ChangedAllBoxes(void)
- {
- register int i;
-
- for (i = kP_ALATCH - kFIRST_PICT; i <= kP_ALU - kFIRST_PICT; ChangedBox(i++))
- ;
- }
-
- /* ActivateObjs: activates (blackens) a list of objects */
-
- void ActivateObjs(const short *objs)
- {
- Rect tempRect;
- GrafPtr savePort;
- short pos;
-
- GetPort(&savePort);
- SetPort(sOffScr);
- PenNormal();
-
- for( ; pos = *objs++; ) {
- register PicHandle tempPicH;
-
- tempPicH = sImages[pos - kFIRST_PICT];
- if( *tempPicH == nil ) /* Resource purged */
- LoadResource((Handle)tempPicH);
- tempRect = (*tempPicH)->picFrame;
- SetPort(sOffScr);
- DrawPicture(tempPicH, &tempRect);
- SetPort(gWPtr_Animation);
- InvalRect(&tempRect);
- }
- SetPort(savePort);
- }
-
- /* DeactivateObjs: deactivates (grays) a list of objects */
-
- void DeactivateObjs(const short *objs)
- {
- Rect tempRect;
- GrafPtr savePort;
- RgnHandle tempRgn = NewRgn();
- RgnHandle tempRgn2 = NewRgn();
- short pos;
-
- GetPort(&savePort);
- SetPort(sOffScr);
- PenPat(&qd.gray);
- PenMode(notPatBic);
-
- for( ; pos = *objs++; ) {
- register PicHandle tempPicH;
-
- tempPicH = sImages[pos - kFIRST_PICT];
- if( *tempPicH == nil ) /* Resource purged */
- LoadResource((Handle)tempPicH);
- tempRect = (*tempPicH)->picFrame;
- SetPort(sOffScr);
- DrawPicture(tempPicH, &tempRect);
- tempRect.right--;
- tempRect.bottom--;
- if(pos <= kP_MIR) {
- if(pos == kP_MIR) {
- CopyRgn(sMirUpdRgn, tempRgn2);
- InvertRgn(sMirUpdRgn);
- }
- else
- RectRgn(tempRgn2, &sRval[pos - kP_ALATCH]);
- RectRgn(tempRgn, &tempRect);
- DiffRgn(tempRgn, tempRgn2, tempRgn);
- }
- else
- RectRgn(tempRgn, &tempRect);
- PaintRgn(tempRgn);
- SetPort(gWPtr_Animation);
- InvalRect(&tempRect);
- }
- DisposeRgn(tempRgn2);
- DisposeRgn(tempRgn);
- SetPort(savePort);
- }
-
- /* Update_Animation: handler for the update event */
-
- void Update_Animation(WindowPtr w, short)
- {
-
- CopyBits(&sOffScr->portBits, &w->portBits, &sOffScr->portBits.bounds,
- &w->portRect, srcCopy, nil);
- }
-
- /* Do_Animation: someone has clicked in … */
-
- void Do_Animation(WindowPtr /*w*/, EventRecord *theEvent)
- {
- //#pragma unused (w)
-
- Rect tempRect;
- Point myPt;
- register short code;
-
- myPt = theEvent->where;
- GlobalToLocal(&myPt);
- if (PtInObj(myPt, &tempRect, code = kP_ALATCH - kFIRST_PICT) ||
- PtInObj(myPt, &tempRect, code = kP_BLATCH - kFIRST_PICT) ||
- PtInObj(myPt, &tempRect, code = kP_MAR - kFIRST_PICT) ||
- PtInObj(myPt, &tempRect, code = kP_MBR - kFIRST_PICT) ||
- PtInObj(myPt, &tempRect, code = kP_AMUX - kFIRST_PICT) ||
- PtInObj(myPt, &tempRect, code = kP_ALU - kFIRST_PICT) ||
- PtInObj(myPt, &tempRect, code = kP_SHIFTER - kFIRST_PICT) ||
- PtInObj(myPt, &tempRect, code = kP_MMUX - kFIRST_PICT) ||
- PtInObj(myPt, &tempRect, code = kP_INCR - kFIRST_PICT) ||
- PtInObj(myPt, &tempRect, code = kP_MPC - kFIRST_PICT) ||
- PtInObj(myPt, &tempRect, code = kP_REGISTERS - kFIRST_PICT) ||
- (PtInObj(myPt, &tempRect, code = kP_CONTSTORE - kFIRST_PICT) && DocIsOpen()) ) {
- if (TrackObject(&tempRect)) {
- if (code == kP_REGISTERS - kFIRST_PICT)
- DoMenuWindows(kMItem_Registers);
- else if (code == kP_CONTSTORE - kFIRST_PICT)
- DoMenuWindows(kMItem_Microprogram);
- else {
- (void)DoEditDialog(code, kPART_NAMES,
- (code >= kP_INCR - kFIRST_PICT) &&
- (code <= kP_MPC - kFIRST_PICT) ? kPOP_DEC : kPOP_HEX);
- UnloadSeg(DoEditDialog);
- }
- }
- }
- }
-
- /* TrackObject: like all the TrackThing in the Mac OS */
-
- Boolean TrackObject(RectPtr r)
- {
- Point myPt;
- register Boolean inrect;
-
- InvertRect(r);
- inrect = true;
- do {
- register Boolean tempB;
-
- GetMouse(&myPt);
- if ((tempB = PtInRect(myPt, r)) != inrect) {
- InvertRect(r);
- inrect = tempB;
- }
- }
- while( StillDown() );
- if (inrect) {
- InvertRect(r);
- }
- return inrect;
- }
-
- /* procedure called when closing the Animation window */
-
- void CloseAnimation(WindowPtr w)
- {
- DoCloseWindow(w, kMItem_Animation);
- }
-
- /* ZoomEffectMap2MPC: the hardware decoding unit is modifying
- the Micro Program Counter; let the user have a visual feedback */
-
- void ZoomEffectMap2MPC(void)
- {
- GrafPtr savePort;
- Rect mapRect, mpcRect;
- PicHandle tempPH;
-
- GetPort(&savePort);
- SetPort(gWPtr_Animation);
- tempPH = sImages[kP_MAP - kFIRST_PICT];
- if (*tempPH == nil)
- LoadResource((Handle)tempPH);
- mapRect = (*tempPH)->picFrame;
- tempPH = sImages[kP_MPC - kFIRST_PICT];
- if (*tempPH == nil)
- LoadResource((Handle)tempPH);
- mpcRect = (*tempPH)->picFrame;
-
- LocalToGlobal(&topLeft(mapRect));
- LocalToGlobal(&botRight(mapRect));
- LocalToGlobal(&topLeft(mpcRect));
- LocalToGlobal(&botRight(mpcRect));
-
- ZoomingRects(&gPrefs.zfr, &mapRect, &mpcRect, zoomDecelerate);
- SetPort(savePort);
- }
-
- #endif
-
-